package com.simplelove.controller;

import com.simplelove.common.Result;
import com.simplelove.entity.HealthCheck;
import com.simplelove.service.HealthCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 健康检查管理控制器
 */
@RestController
@RequestMapping("/api/health-checks")
public class HealthCheckController {
    
    @Autowired
    private HealthCheckService healthCheckService;
    
    /**
     * 同步健康检查数据
     */
    @PostMapping("/sync")
    public Result<List<HealthCheck>> syncHealthChecks(
            @RequestParam Long userId,
            @RequestBody List<HealthCheck> healthChecks) {
        try {
            List<HealthCheck> result = healthCheckService.syncHealthChecks(userId, healthChecks);
            return Result.success("同步成功", result);
        } catch (Exception e) {
            return Result.error("同步失败: " + e.getMessage());
        }
    }
    
    /**
     * 获取健康检查数据
     */
    @GetMapping
    public Result<List<HealthCheck>> getHealthChecks(@RequestParam Long userId) {
        try {
            List<HealthCheck> healthChecks = healthCheckService.getUserHealthChecks(userId);
            return Result.success("获取成功", healthChecks);
        } catch (Exception e) {
            return Result.error("获取失败: " + e.getMessage());
        }
    }
}
